<template>
  <div>
    <!--条件筛选-->
    <TopFilter :list="topFilterList" :cols="3" labelWidth="110" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <!--操作 -->
    <button-area :style="{ paddingLeft: '80px' }"></button-area>
    <!-- 列筛选-->
    <FilterTable
      ref="table"
      columnsRef="whm"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'rows'"
      :isSelectColumn="boolear"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectData"
    >
      <!--列操作-->
      <template slot="controls"> </template>
    </FilterTable>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { searchRoleByCode } from '@/api/common/empSelect/index';
import { getQueryAccountsModel, getAllUser } from '@/api/repair/queryStatistics/queryAccounts';
import ReportModal from './reportModal';

export default {
  name: 'LHMChangeCustomerGradeUp',
  mixins: [dictionary],
  props: {
    rowData: {
      type: Object,
      default: () => ({})
    }
  },

  data() {
    this.conf = { add: '新增', delete: '删除', edit: '编辑', show: '显示' };
    return {
      topFilterList: this.createTopFilterList(),
      visible: false,
      visible1: false,
      boolear: false,
      dialogTitle: '',
      fetchApi: getQueryAccountsModel,
      fetchParams: { roNo: this.rowData[0].RO_NO },
      columns: this.createTableColumns(),
      handleType: '',
      formData: {},
      tableData: [],
      ids: []
    };
  },
  created() {
    this.init();
    this.getAllUser();
  },

  mounted() {
    // 分页
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
    createTopFilterList() {
      return [
        {
          type: 'RANGE_DATE',
          label: '日期范围',
          fieldName: 'beginDate|endDate',
          placeholder: '选择日期'
        }
      ];
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '编号',
          dataIndex: 'RO_NO',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '当次收款金额',
          dataIndex: 'RECEIVE_AMOUNT',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '欠款金额',
          dataIndex: 'ARREARAGE_AMOUNT',
          sorter: true,
          hidden: true,
          filter: true,
          filterType: 'input'
        },

        {
          title: '会员消费金额',
          dataIndex: 'MEMBER_AMOUNT',
          sorter: true,
          filter: true,
          filterType: 'number'
        },
        {
          title: '结算日期',
          dataIndex: 'BALANCE_TIME',
          width: 150,
          dateFormat: 'yyyy-MM-dd',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          editable: false,
          editType: 'date-picker'
        },
        {
          title: '结算人',
          dataIndex: 'BALANCE_HANDLER',
          sorter: true,
          filter: true,
          filterType: 'input',
          editType: 'select',
          editItems: []
        }
      ];
    },
    selectData(val) {
      this.tableData = val;
    },
    addHandle() {
      // 新建
      this.handleType = 'add';
      this.showHandler();
    },
    editHandle(row) {
      this.handleType = 'edit'; // 编辑
      this.formData = row;
      this.showHandler();
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({ roNo: this.rowData[0].RO_NO }, val);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },

    init() {
      console.log(this.rowData);
      // this.columns.find(item => item.dataIndex === 'BALANCE_HANDLER').initialValue=this.rowData[0].RO_NO;
      // this.formList.forEach(x => {
      //   x.initialValue = this.rowData[x.fieldName];
      // });
    },
    async getAllUser() {
      let testDrive = { role: '' };
      const res = await searchRoleByCode(testDrive);
      console.log(res, '服务顾问122222222');
      this.columns.find(item => item.dataIndex === 'BALANCE_HANDLER').editItems = res.data.map(x => ({ value: x.userId + '', text: x.employeeName }));
    },
    showHandler() {
      // 显示
      this.dialogTitle = `更改历史`;
      this.visible = true;
    },
    closeHandler(val, type) {
      // 关闭
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    }
  }
};
</script>

<style lang="less" scoped></style>
